#include"../../client/rpc_client.hpp"
#include"../../common/detail.hpp"

void callback(const Json::Value &result)
{
    delog("callback结果：%d", result.asInt());
    std::cout << result.asInt() << std::endl;
}

int main()
{
    rpc::client::RpcClient client(true, "127.0.0.1", 8080);
    Json::Value pramas;
    rpc::client::RpcCaller::JsonAsync res_future;
    Json::Value result;
    bool ret = false;

    pramas["num1"] = 11;
    pramas["num2"] = 12;
    delog("client开始调用方法");
    ret = client.call("Add", pramas, result);
    delog("client结束调用方法");
    if (ret)
    {
        std::cout << result.asInt() << std::endl;
    }
    pramas["num1"] = 50;
    pramas["num2"] = 60;
    delog("client开始调用方法");
    ret = client.call("Add", pramas, res_future); // 并不会阻塞
    delog("client结束调用方法");
    if (ret)
    {
        delog("异步调用结果");
        result = res_future.get(); // 用户调用后才会获取结果
        std::cout << result.asInt() << std::endl;
    }

    pramas["num1"] = 90;
    pramas["num2"] = 60;
    delog("client开始回调方法");
    ret = client.call("Add", pramas, callback); // 并不会阻塞
    delog("client结束回调方法");
    sleep(10);
    return 0;
}